package com.iemes.controller.finance;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.LossFormMap;
import com.iemes.mapper.finance.LossMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/finance")
@Controller
public class LossController extends BaseController {

	@Inject
	private LossMapper lossMapper;

	@RequestMapping("loss")
	public String loss(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/finance/shipmentmanagement/loss_list";
	}
	
	@ResponseBody
	@RequestMapping("loss_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		LossFormMap lossFormMap = getFormMap(LossFormMap.class);
		List<Map<String,Object>> loss=lossMapper.getLossByCondition(lossFormMap);
		System.out.println("土狗"+loss.size());
		LuogicPaging(pageNow, pageSize, loss);
		pageView.setRecords(loss);
		return pageView;
	}
	
	
	@RequestMapping("loss_edit")
	public String editUI(Model model) throws Exception 
	{
		String id = getPara("id");
		LossFormMap lossFormMap=lossMapper.getLossById(Integer.parseInt(id));
		model.addAttribute("lossFormMap", lossFormMap);
		return Common.BACKGROUND_PATH + "/finance/shipmentmanagement/loss_edit";
	}
	
	
	@ResponseBody
	@RequestMapping(value="loss_editEntity")
	@SystemLog(module="差异损耗报表",methods="损耗报表-修改客户耗率")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		
		LossFormMap lossFormMap = getFormMap(LossFormMap.class);
		lossMapper.editEntity(lossFormMap);
		return "success";
	}
	
	
	@ResponseBody
	@RequestMapping(value="loss_deleteEntity")
	@SystemLog(module="差异损耗报表",methods="损耗报表-删除物料")//凡需要处理业务逻辑的.都需要记录操作日志
	public String deleteEntity() throws Exception {
		LossFormMap lossFormMap = getFormMap(LossFormMap.class);
		String[] ids = getParaValues("ids");
		String arr=ids[0];
		String[] str=arr.split(",");
		for(int i=0;i<str.length;i++){
			lossFormMap.put("state", 1);
			lossFormMap.put("id", str[i]);
			lossMapper.editEntity(lossFormMap);
		}
		return "success";
	}
	
	
}
